﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// Gaussian Blur
    /// </summary>
    public class GaussianBlur : BaseImageFilter
    {
        protected int m_nWeight = 4;
        CConvMatrix matrix = new CConvMatrix();

        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianBlur"/> class.
        /// </summary>
        public GaussianBlur()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianBlur"/> class.
        /// </summary>
        /// <param name="_nWeight">The _n weight.</param>
        public GaussianBlur(int _nWeight)
        {
            m_nWeight = _nWeight;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianBlur"/> class.
        /// </summary>
        /// <param name="_gaussianBlur">The _gaussian blur.</param>
        internal GaussianBlur(GaussianBlur _gaussianBlur)
        {
            this.m_nWeight = _gaussianBlur.m_nWeight;
        }

        /// <summary>
        /// Gets or sets the weight.
        /// </summary>
        /// <value>The weight.</value>
        public int Weight
        {
            get { return m_nWeight; }
            set { m_nWeight = value; }
        }

        /// <summary>
        /// Execute this Filter
        /// A Debug Statement is written if a concrete Filter is called
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {   
			matrix.SetAll(1);
			matrix.Pixel = m_nWeight;
			matrix.TopMid = matrix.MidLeft = matrix.MidRight = matrix.BottomMid = 2;
			matrix.Factor = m_nWeight + 12;
			new Convolution3x3(matrix).Execute(_bitmap);
            return _bitmap;
		}

        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new GaussianBlur(this);
        }
    }
}
